﻿@using System.Globalization
@namespace Masa.Docs.Core.Components
@inject AppService AppService
@inject I18n I18n

<AppSheet MinHeight="@((StringNumber)61)">
    <MListItem Href="@Href" Disabled="@Disabled">
        <MListItemIcon>
            <MIcon Color="@Color">@Icon</MIcon>
        </MListItemIcon>

        <MListItemContent>
            <MListItemTitle>@I18n.T(Title)</MListItemTitle>
            <MListItemSubtitle>@I18n.T(Subtitle)</MListItemSubtitle>
        </MListItemContent>
    </MListItem>
</AppSheet>

@code {

    [CascadingParameter(Name = "Culture")]
    private string Culture { get; set; } = null!;

    /// <summary>
    /// The href.
    /// </summary>
    /// <example>/{category}/{title}</example>
    [EditorRequired]
    [Parameter]
    public string Href { get; set; }

    #region Unsupport hrefs

    // TODO: Delete the code if unsupported hrefs is empty.

    readonly List<string> _unsupportedHrefs = new()
    {
        "/blazor/features/theme",
        "/blazor/components/parallax",
        "/blazor/components/selection-controls",
        "/blazor/components/combobox"
    };

    bool Disabled => _unsupportedHrefs.Contains(Href);

    #endregion

    readonly Dictionary<string, (string icon, string color)> _categories = new()
    {
        { "api", ("mdi-flask-outline", "orange") },
        { "components", ("mdi-view-dashboard-outline", "indigo darken-1") },
        { "features", ("mdi-image-edit-outline", "red") },
        { "directives", ("mdi-function", "blue-grey") },
        { "getting-started", ("mdi-speedometer", "teal") },
        { "introduction", ("mdi-script-text-outline","green") },
        { "about", ("mi-masa","primary") },
        { "resources", ("mdi-human-male-board","pink") },
        { "styles-and-animations", ("mdi-palette-outline","deep-purple accent-4") },
        { "themes", ("mdi-script-text-outline", "pink") },
    };

    private string? Title => Href.Split("/").ElementAtOrDefault(3);

    public string? Subtitle => Href.Split("/").ElementAtOrDefault(2);

    private string? Color => Subtitle is not null && _categories.TryGetValue(Subtitle, out var value) ? value.color : null;

    private string? Icon => Subtitle is not null && _categories.TryGetValue(Subtitle, out var value) ? value.icon : null;

}
